﻿using MediatR;
using RBAC.Common.Domains;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.RBAC
{
    public class PermissionAddHander:IRequestHandler<PermissionAddCommand, Rulst>
    {

        private readonly IbaseRpository<Permission> _permission;

        public PermissionAddHander(IbaseRpository<Permission> permission)
        {
            _permission = permission;
        }

        public async Task<Rulst> Handle(PermissionAddCommand request, CancellationToken cancellationToken)
        {
            var list = new Rulst() { Code = (int)Reult.success };



            var permission = new Permission()
            {
                isyes=request.isyes,
                Permissionid=0,
                PermissionName=request.PermissionName,
                pid=request.pid,
                URl=request.URl,
            };



            var reslult=_permission.Add(permission);


            if(reslult>0)
            {
            
                    list.Code = (int)Reult.Addad;
            
            }

            return list;


        }

       
    }
}

